package com.sl.biz.modular.office.service.impl;

import cn.hutool.core.util.StrUtil;
import com.sl.biz.modular.office.dao.domain.entity.OfficeRecordDO;
import com.sl.biz.modular.office.dao.service.OfficeRecordContentDaoService;
import com.sl.biz.modular.office.dao.service.OfficeRecordDaoService;
import com.sl.biz.modular.office.service.OfficeRecordBizService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class OfficeRecordBizServiceImpl implements OfficeRecordBizService {

    private final OfficeRecordDaoService officeRecordDaoService;


    private final OfficeRecordContentDaoService officeRecordContentDaoService;

    protected Boolean add(OfficeRecordDO officeRecord) {
        return officeRecordDaoService.save(officeRecord);
    }

    @Override
    public String save(OfficeRecordDO officeRecord) {
        String id = officeRecord.getId();
        if (StrUtil.isNotBlank(id)) {
             updateById(officeRecord);
             return id;
        }
         add(officeRecord);
        return officeRecord.getId();
    }

    @Override
    public List<OfficeRecordDO> list(OfficeRecordDO jobConfigDO) {
        return officeRecordDaoService.list(jobConfigDO);
    }

    @Override
    public OfficeRecordDO getById(OfficeRecordDO officeRecordDO) {
        return officeRecordDaoService.getById(officeRecordDO.getId());
    }

    @Override
    public Boolean removeById(OfficeRecordDO officeRecordDO) {
        officeRecordContentDaoService.removeByOfficeId(officeRecordDO.getId());
        officeRecordDaoService.removeById(officeRecordDO.getId());
        return Boolean.TRUE;
    }

    protected Boolean updateById(OfficeRecordDO updateByIdRequest) {
        return officeRecordDaoService.updateById(updateByIdRequest);
    }
}
